package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.pojo.ParkPointBound;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.ParkFunctionService;
import com.tbit.uqbike.webmanager.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @Author:
 * @Description: RFId绑定
 * @Date:
 */
@RequestMapping(value = "/parkFunction")
@RestController
public class ParkFunctionController {
    @Autowired
    private ParkFunctionService parkFunctionService;

    @RequestMapping("/queryPage")
    public JsonResult queryPage(Integer state, Integer parkPointId, String machineNO, Integer type,
                                @RequestParam(defaultValue = "1") Integer pageNO, @RequestParam(defaultValue = "10") Integer rowCount) {
        Assert.notNull(parkPointId, "ver.parkPointId.notNull");
        List<ParkPointBound> list = parkFunctionService.queryPage(state, parkPointId, machineNO, type, pageNO, rowCount);
        Integer total = parkFunctionService.queryCount(state, parkPointId, machineNO, type);
        return JsonResult.ok(list, total);
    }

    @RequestMapping("/add")
    public JsonResult insert(ParkPointBound parkPointBound) {
        Assert.notNull(parkPointBound.getParkPointId(), "ver.parkPointId.notNull");
        Assert.notNull(parkPointBound.getFunctionNo(), "ver.functionNo.notNull");
        parkFunctionService.insert(parkPointBound);
        return JsonResult.ok();
    }

    /**
     * 批量添加
     *
     * @param parkPointId
     * @param functionNos
     * @return
     */
    @RequestMapping("/addBatch")
    public JsonResult addBatch(Integer parkPointId, String functionNos) {
        Assert.notNull(parkPointId, "ver.parkPointId.notNull");
        Assert.notNull(functionNos, "ver.functionNo.notNull");
        List<String> list = Arrays.asList(functionNos.split(","));
        parkFunctionService.addBatch(parkPointId, list);
        return JsonResult.ok();
    }

    @RequestMapping("/del")
    public JsonResult del(String functionNo) {
        Assert.notNull(functionNo, "ver.functionNo.notNull");
        parkFunctionService.del(functionNo);
        return JsonResult.ok();
    }

}
